package com.wzy.content.api;

import com.wzy.content.model.dto.BindTeachplanMediaDto;
import com.wzy.content.model.dto.SaveTeachplanDto;
import com.wzy.content.model.dto.TeachplanDto;
import com.wzy.content.model.po.TeachplanMedia;
import com.wzy.content.service.TeachplanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author wzy
 * @Date 2023/12/29 13:32
 * @description: 课程计划信息管理接口
 */
@RestController
@Api(value = "课程计划信息管理接口",tags = "课程计划信息管理接口")
public class TeachplanController {
    @Autowired
    private TeachplanService teachplanService;

    @ApiOperation("查询课程计划树形结构")
    @GetMapping("/teachplan/{courseId}/tree-nodes")
    public List<TeachplanDto> getTreeNodes(@PathVariable Long courseId){

        return teachplanService.getTeachPlanTree(courseId);
    }
    @ApiOperation("课程计划创建或修改")
    @PostMapping("/teachplan")
    public void saveTeachPlan( @RequestBody SaveTeachplanDto saveTeachplanDto){
        teachplanService.updateTeachPlan(saveTeachplanDto);
    }

    @ApiOperation("删除课程目录")
    @DeleteMapping("/teachplan/{teachPlanId}")
    public void deleteTeachPlanById(@PathVariable Long teachPlanId){
        teachplanService.deleteTeachPlaById(teachPlanId);
    }
    @ApiOperation("移动课程计划顺序")
    @PostMapping("/teachplan/{moveType}/{teachPlanId}")
    public void moveTeachPlanById(@PathVariable String moveType,@PathVariable Long teachPlanId){
        teachplanService.moveTeachPlanById(moveType,teachPlanId);
    }

    @ApiOperation(value = "课程计划和媒资信息绑定")
    @PostMapping("/teachplan/association/media")
    public void associationMedia(@RequestBody BindTeachplanMediaDto bindTeachplanMediaDto){
        teachplanService.associationMedia(bindTeachplanMediaDto);
    }
    @ApiOperation(value = "课程计划解除视频绑定")
    @DeleteMapping ("/teachplan/association/media/{teachPlanId}/{mediaId}")
    public void mediaUnAssociation(@PathVariable Long teachPlanId,@PathVariable String mediaId){
        teachplanService.mediaUnAssociation(teachPlanId,mediaId);
    }
    @ApiOperation(value = "根据媒资id查询相关课程计划")
    @GetMapping ("/media/{mediaId}")
    public List<TeachplanMedia> getTeachPlanByMediaId( @PathVariable String mediaId){
        List<TeachplanMedia> teachplanMedias = teachplanService.getTeachPlanByMediaId(mediaId);
        return teachplanMedias;
    }


}
